//Programs TABLE7(PartII)A and TABLE7(PartII)B produce the panel time data results in TABLE 7.
//The programs are intended to be run in tandem, with program A run first.
//It takes approximately 1 hour and 10 minutes on a laptop to run 10,000 iterations.

etime, start
log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\HURWICZ BIAS\REVISION FOR ECONOMIC MODELLING\PROGRAMS2\TABLE7(PartII).smcl", replace
drop _all
clear
graph drop _all
set more off
set seed 13

matrix medLRP = J(4,2,0)
matrix confidLRP = J(4,4,0)
matrix meanRR = J(4,2,0)

// The local commands below set all the parameters for the experiments.
local numN = 50 // This sets the number of cross-sectional units
local numT = 80
local beta0 = 0 // This sets the intercept term
local betax = 1 // This sets the slope coefficient for x
local reps = 10000

local i = 1
foreach betay in 0.60 0.90 {
foreach rhox in 0 1 {
local j = 1
   foreach smallt in 70 55 {
      simulate LRP = r(LRP) pLRP = r(pLRP), ///
         reps(`reps'): TABLE7prog, beta0(`beta0') betax(`betax') betay(`betay') ///
		 rhox(`rhox') smallt(`smallt') numN(`numN') numT(`numT')
		 
		  summ LRP, detail
		  matrix medLRP[`i', `j'] = r(p50)
		  matrix confidLRP[`i',1+(`j'-1)*2] = r(p5)
		  matrix confidLRP[`i',2+(`j'-1)*2] = r(p95)
		  generate RejectRate = 0
		  replace RejectRate = 1 if pLRP < 0.05  
		  summ RejectRate, meanonly
		  matrix meanRR[`i',`j'] = r(mean)
		local `++j'
		}
	local `++i'
	}
}

matrix colnames medLRP = "N50:T10" "N50:T25"
matrix rownames medLRP= R00B60 R100B60 R00B90 R100B90

matrix colnames confidLRP = "N50:T10(P5)" "N50:T10(P95)" "N50:T25(P5)" "N50:T25(P95)"
matrix rownames confidLRP = R00B60 R100B60 R00B90 R100B90

matrix colnames meanRR = "N50:T10" "N50:T25"
matrix rownames meanRR = R00B60 R100B60 R00B90 R100B90

matrix list medLRP
matrix list confidLRP
matrix list meanRR

etime

log close
